package com.miracle.main.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.miracle.common.util.TimeUtil;
import com.miracle.main.R;
import com.miracle.main.adapter.viewholder.TimeLineViewHolder;
import com.miracle.main.module.mvp.entity.bean.SecretBean;

import java.util.ArrayList;

/**
 * com.miracle.main.adapter
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/6 17:22
 * @see com.miracle.main.adapter
 */
public class SecreteAdapter extends RecyclerView.Adapter<TimeLineViewHolder> {

    Context mContext;
    LayoutInflater mLayoutInflater;
    ArrayList<SecretBean> mList;
    private static final int EXCITED = R.drawable.icon_excited;
    private static final int HAPPY = R.drawable.icon_happy;
    private static final int NORMAL = R.drawable.icon_normal;
    private static final int SAD = R.drawable.icon_sad;
    private static final int SAD_2 = R.drawable.icon_sx;

    public SecreteAdapter(ArrayList<SecretBean> list) {
        mList = list;
    }

    @Override
    public TimeLineViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext = parent.getContext();
        mLayoutInflater = LayoutInflater.from(mContext);
        View view;

        view = mLayoutInflater.inflate(R.layout.cloud_item_timeline, parent, false);

        return new TimeLineViewHolder(view, viewType);
    }

    @Override
    public void onBindViewHolder(TimeLineViewHolder holder, int position) {
        SecretBean timeLineModel = mList.get(position);
//        if (!timeLineModel.getmDate().isEmpty()) {
//            holder.mDate.setVisibility(View.VISIBLE);
////            holder.mDate.setText(DateTimeUtils.parseDateTime(timeLineModel.getmDate(),
//// "yyyy-MM-dd" +
////                    " HH:mm", "hh:mm a, dd-MMM-yyyy"));
//            holder.mDate.setText("2018-7-7 18:00:06");
//        } else {
//            holder.mDate.setVisibility(View.GONE);
//        }
        holder.mMessage.setText(timeLineModel.getText());
        holder.mDate.setVisibility(View.VISIBLE);
        holder.mDate.setText(TimeUtil.getDateToString(timeLineModel.getCreTime(), TimeUtil
                .Pattern.TIME));
        int drawable = EXCITED;
        int bgColor = R.color.colorPrimary;
        if (TextUtils.isEmpty(timeLineModel.getMood())) {
            holder.mIvMood.setImageResource(drawable);
            return;
        }
        switch (timeLineModel.getMood()) {
            case "1":
                drawable = HAPPY;
                bgColor = R.color.c17;
                break;
            case "2":
                drawable = NORMAL;
                bgColor = R.color.c17;
                break;
            case "3":
                drawable = SAD;
                bgColor = R.color.c17;
                break;
            default:
                drawable = HAPPY;
                bgColor = R.color.c17;
                break;
        }
        holder.mIvMood.setImageResource(drawable);
//        holder.mLL.setBackgroundColor(ContextCompat.getColor(mContext, bgColor));

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }
}
